package com.fingerth.crawler.room

import androidx.room.*

@Dao
interface NovelCollectionDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(novel: NovelCollection)

    @Update
    fun update(novel: NovelCollection)

    @Delete
    fun delete(vararg novel: NovelCollection)


    @Query("SELECT COUNT(*) FROM NovelCollection")
    fun count(): Int

    @Query("SELECT COUNT(*) FROM NovelCollection WHERE fictionType LIKE '%' || :type || '%'")
    fun countByType(type: String): Int


//    @Query("SELECT * FROM NovelCollection WHERE fictionId != '0' AND lastTime > 0 ORDER BY lastTime DESC LIMIT :size OFFSET :index ")
//    fun queryHistory(index: Int, size: Int): Array<NovelCollection>

    @Query("SELECT * FROM NovelCollection ORDER BY id DESC LIMIT 1 OFFSET :index ")
    fun queryByIndex(index: Int): NovelCollection

    @Query("SELECT * FROM NovelCollection WHERE fictionId == :fictionId")
    fun queryById(fictionId: String): NovelCollection?

}